package com.xuanheng.utils.http;


import com.xuanheng.utils.http.async.AsyncHttpClient;
import com.xuanheng.utils.http.async.IResponseHandler;
import com.xuanheng.utils.http.async.RequestParams;

/**
 * @author Created by liyh on 2017/1/18.
 * @function 使用HttpUrlConnection发送请求的http请求的client
 */
public class CommonHttpClient {

    public static final int DEFAULT_TIME_OUT = 2000;

    private AsyncHttpClient httpClient;
    private static CommonHttpClient ourInstance = new CommonHttpClient();

    public static CommonHttpClient getInstance() {
        return ourInstance;
    }

    private CommonHttpClient() {
        httpClient = new AsyncHttpClient();
        //TODO UA
//        httpClient.setUserAgent("Youku;6.8.5.2;Android;7.0;VTR-AL00");
//        httpClient.setUserAgent(DeviceInfo.getDefaultUserAgent());
    }

    public void get(int timeOut, String url, RequestParams params, Class clazz, ParseDataListener parseDataListener) {
        httpClient.get(url, timeOut, params, parseDataListener);
    }


    public void get(String url, RequestParams params, Class clazz, ParseDataListener parseDataListener) {
        httpClient.get(url, DEFAULT_TIME_OUT, params, parseDataListener);
    }

    public void post(String url, RequestParams params, Class clazz, ParseDataListener parseDataListener) {
        httpClient.post(url, DEFAULT_TIME_OUT, params, parseDataListener);
    }

    public void get(String url) {
        httpClient.get(url, null, true, null);
    }

    public void get(String url, boolean can302) {
        httpClient.get(url, null, can302, null);
    }

    public void get(String url, boolean can302, IResponseHandler responseHandler) {
        httpClient.get(url, null, can302, responseHandler);
    }

    public void get(String url, IResponseHandler responseHandler) {
        httpClient.get(url, null, true, responseHandler);
    }

    public void get(String url, int timeout, IResponseHandler responseHandler) {
        httpClient.get(url, timeout, null, responseHandler);
    }

    public void get(String url, RequestParams params, IResponseHandler responseHandler) {
        httpClient.get(url, DEFAULT_TIME_OUT, params, responseHandler);
    }

    public void post(String url, RequestParams params, IResponseHandler responseHandler) {
        httpClient.post(url, DEFAULT_TIME_OUT, params, responseHandler);
    }
}
